import axios from 'axios';

const BASE_URL = 'http://localhost:8080/Flights';



//通过出发地和目的地获取航班列表
export const getFlightByCFCityAndDDCity = async (CFCity, DDCity) => {
    try {
        const response = await axios.get(`${BASE_URL}/getFlightByCFCityAndDDCity`, {
            params: { CFCity, DDCity }
        });
        return response.data;
    } catch (error) {
        console.error('Error getting flight by cities:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//获取所有航班记录
export const listFlights = async () => {
    try {
        const response = await axios.get(BASE_URL);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//更新航班
export const updateFlight = async (flight) => {
    try {
        const response = await axios.put('http://localhost:8080/Flights', flight);
        return response.data;
    } catch (error) {
        console.error('Error registering user:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//增加航班
export const addFlight = async (flight) => {
    try {
        const response = await axios.post('http://localhost:8080/Flights', flight);
        return response.data;
    } catch (error) {
        console.error('Error registering user:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//删除航班
export const deleteFlight = async (id) => {
    try {
        const response = await axios.delete(`http://localhost:8080/Flights/${id}`);
        return response.data;
    } catch (error) {
        console.error('Error registering user:', error.response ? error.response.data : error.message);
        throw error;
    }
};



